package top.my.utils;

import java.security.MessageDigest;

public class StrUtils {
    public static String md5(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            byte[] bytes = md.digest(s.getBytes("utf-8"));
            final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
            StringBuilder ret = new StringBuilder(bytes.length * 2);
            for (int i = 0; i < bytes.length; i++) {
                ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]);
                ret.append(HEX_DIGITS[bytes[i] & 0x0f]);
            }
            return ret.toString();
        } catch (Exception e) {
            return null;
        }
    }

    public static boolean isNotEmpty(String s) {
        return s != null && s.length() != 0;
    }

    public static boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }

    public static String getToken(long uid) {
        return md5(String.valueOf(uid) + String.valueOf(System.currentTimeMillis()));
    }
}
